import * as THREE from 'three'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'

const gltfLoader = new GLTFLoader()
const audioLoader = new THREE.AudioLoader()
const textureLoader = new THREE.TextureLoader()

export function jiaZaiZiYuan(diZhi) {
	const houZhui = diZhi.match(/(?:\w+)\.(\w+)$/)[1]
	return new Promise((resolve, reject) => {
		switch (houZhui) {
			case 'glb':
				gltfLoader.load(diZhi, z => resolve(z))
				break
			case 'png':
			case 'jpg':
				textureLoader.load(diZhi, z => resolve(z))
				break
			case 'mp3':
				audioLoader.load(diZhi, z => resolve(z))
				break
			default:
				reject()
		}
	})
}
